import axs from './interceptor'

let prefixUrl = '';

/**
 * 普通post
 * @param url
 * @param params
 * @returns {Promise<any>}
 */
export function post(url, params) {
    return new Promise((resolve, reject) => {
        axs({
            url: prefixUrl + url,
            method: 'post',
            params: params
        }).then(response => {
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * post, 参数在requestBody中
 * @param url
 * @param params
 * @returns {Promise<any>}
 */
export function postBody(url, params) {
    return new Promise((resolve, reject) => {
        axs({
            url: prefixUrl + url,
            method: 'post',
            data:params
        }).then(response => {
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * get请求
 * @param url
 * @param params
 * @returns {Promise<any>}
 */
export function get(url, params) {
    return new Promise((resolve, reject) => {
        axs({
            url: prefixUrl + url,
            method: 'get',
            params:params
        }).then(response => {
            resolve(response)
        }).catch(error => {
            reject(error)
        })
    })
}
